﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CapstoneProjectAEReader.Entities.Models;
//using CapstoneProjectAEReader.Common.Utility;
using eBdb.EpubReader;
using System.Threading;

namespace EpubReaderControlLibrary
{
    public class EbookObjectGenerator
    {
        public Ebook GenerateEbookObj(string filePath)
        {
            Ebook myEbook = new Ebook();
            //File type
            FileInfo temp = new FileInfo(filePath);
            if (temp.Extension.Equals(".epub", StringComparison.InvariantCultureIgnoreCase))
            {
                myEbook.Type = ".epub";
            }
            //Create Ebook MetaData

            Epub getEpubBook = new Epub(filePath);
            string activePageCount = getEpubBook.GetContentAsHtml();
            myEbook.Title = "Unknown";
            if (getEpubBook.Title[0] != null)
            {
                myEbook.Title = getEpubBook.Title[0];
            }
            if (getEpubBook.Creator[0] != null)
            {
                myEbook.Author = getEpubBook.Creator[0];
            }
            if (getEpubBook.Publisher[0] != null)
            {
                myEbook.Publisher = getEpubBook.Publisher[0];
            }
            myEbook.Path = filePath;
            myEbook.ImportDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            myEbook.Rating = 0;
            myEbook.CurrentPage = 0;
            myEbook.BookmarkPath = "AeReaderData\\Temp\\" + myEbook.Title + ".xml";
            myEbook.PageCount = getEpubBook.epubPage;

            return myEbook;
        }
    }
}
